package com.eascs.admin.o2o.oper.dao;

import org.springframework.stereotype.Repository;

import com.eascs.admin.common.dao.BaseO2oDao;
import com.eascs.admin.o2o.oper.entity.O2oOperationUploanlogForm;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.common.util.DateUtils;
import com.eascs.common.util.StringUtil;

@Repository
public class O2oOperationUploanlogDao  extends BaseO2oDao {

	public PageResult<Object[]> queryBypage(O2oOperationUploanlogForm form){
		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, form.getPageSize(), form.getPageIndex());
		StringBuffer querySql = new StringBuffer();
		querySql.append("select bill_code,up_user_name,up_time,up_remark from o2o_operation_uploanlog where 1=1");
		if(StringUtil.isNotBlank(form.getBillCode())){
			querySql.append(" and bill_code like ?");
			sqlPageQuery.addLikeParam(form.getBillCode());
		}
		if(StringUtil.isNotBlank(form.getUpUserName())){
			querySql.append(" and up_user_name like ?");
			sqlPageQuery.addLikeParam(form.getUpUserName());
		}
		if(StringUtil.isNotBlank(form.getUpStartTime())){
			querySql.append(" and up_time >= ?");
			sqlPageQuery.addParam(form.getUpUserName());
		}
		if(StringUtil.isNotBlank(form.getUpEndTime())){
			querySql.append(" and up_time < ?");
			sqlPageQuery.addParam(DateUtils.formateStandDate(DateUtils.addDate(DateUtils.formateStandDate(form.getUpEndTime()), 1)));
		}
		querySql.append(" order by up_time desc");
		sqlPageQuery.setQuerySql(querySql.toString());
		return this.findDataWithPage(sqlPageQuery);
	}
}
